package com.neu;

import com.neu.utils.zookeeper.ZookeeperNode;
import com.neu.utils.zookeeper.ZookeeperUtils;

import java.util.Arrays;
import java.util.List;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooKeeper;

/**
 * 注册中心的管理界面
 * @author 杜佳辉
 * @version 1.0
 * @date 2024-12-05-21:19
 */
public class Application {
    // 帮我们创建基础目录
    // rpc-metadata   (持久节点)
    //  └─ providers （持久节点）
    //  		└─ service1  （持久节点，接口的全限定名）
    //  		    ├─ node1 [data]     /ip:port
    //  		    ├─ node2 [data]
    //            └─ node3 [data]
    //  └─ consumers
    //        └─ service1
    //             ├─ node1 [data]
    //             ├─ node2 [data]
    //             └─ node3 [data]
    //  └─ config
    public static void main(String[] args) {
        // 创建一个zookeeper实例
        ZooKeeper zooKeeper = ZookeeperUtils.createZookeeper();

        // 定义节点和数据
        String basePath = "/rpc-metadata";
        String providerPath = basePath + "/providers";
        String consumersPath = basePath + "/consumers";
        ZookeeperNode baseNode = new ZookeeperNode(basePath, null);
        ZookeeperNode providersNode = new ZookeeperNode(providerPath, null);
        ZookeeperNode consumersNode = new ZookeeperNode(consumersPath, null);

        // 创建节点
//        List.of(baseNode, providersNode, consumersNode).forEach(node -> {
//            ZookeeperUtils.createNode(zooKeeper,node,null, CreateMode.PERSISTENT);
//        });
        // 创建节点
        List<ZookeeperNode> nodes = Arrays.asList(baseNode, providersNode, consumersNode);
        nodes.forEach(node -> ZookeeperUtils.createNode(zooKeeper, node, null, CreateMode.PERSISTENT));



        // 关闭连接
        ZookeeperUtils.close(zooKeeper);
    }
}
